<template>
	<view class="container">
		<!-- 内容区域包装器 -->
		<view class="content-wrapper">
			<!-- 搜索区域 -->
			<view class="search-box">
				<u-search placeholder="请输入关键搜索" v-model="fromData.keyword" :show-action="false" :clearabled="true"
					:animation="false" shape="round" bgColor="#F5F6FA" height="72rpx" searchIconColor="#999999"
					placeholderColor="#999999" @change="changekeword" :inputStyle="{
						color: '#333333',
						backgroundColor: '#F5F6FA',
					}"></u-search>
			</view>
		</view>
		<view class="content-box">
			<view class="content-total">
				共 {{total}} 条记录，点击选择
			</view>
			<view class="empty-review" v-if="list.length == 0">
				<image src='../static/images/empty-review.png' mode="aspectFit"></image>
			</view>
			<view class="empty-review" v-if="list.length == 0">
				<image src='../static/images/empty-review.png' mode="aspectFit"></image>
			</view>
			<view class="content-list">
				<view class="content-item" v-for="item in list" :key="item.id" @click="handleClick(item)">
					<view class="content-item-top">
						<view class="content-item-title">
							<u-icon name="bell-fill" color="#FE4F04" size="30rpx"></u-icon>
							{{item.title}}
						</view>
						<view class="content-item-date"></view>
					</view>
					<view class="content-item-text">
						<rich-text :nodes="item.content"></rich-text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>


<script>
		import { noticeTemplate } from "@/api/part2.js";
	export default {
		data() {
			return {
				fromData: {
					page: 1,
					limit: 10,
					keyword: ''
				},
				total: 7,
				list: [	]
			};
		},
		onLoad(options) {
			this.init()
		},
		async onReachBottom() {
			this.fromData.page++
			this.init()
		},
		methods: {
			changekeword() {
				this.fromData.page=1
				this.init()
			},
			init() {
				noticeTemplate(this.fromData).then(res => {
					console.log(res.data.data);
					res.data.data.data.forEach((item) => {
						this.list.push(item)
					})
					this.total = res.data.data.total
				})
			},
		handleClick(template){
			console.log(template)
			uni.navigateBack({
					delta: 1,
					success: () => {
							// 通过事件或全局方式传参
							uni.$emit('templateSelected', template);
					}
			});
		}
		},
	};
</script>

<style lang="less" scoped>
	.search-box {
		padding: 12rpx 20rpx 24rpx 32rpx;
		background-color: #fff;
	}

	.add-btn {
		padding: 20rpx;
	}

	.content-box {
		padding: 0 32rpx;
	}

	.content-total {
		padding: 16rpx 0;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 22rpx;
		color: #999999;
	}

	.content-item {
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 0, 0, 0.01);
		border-radius: 24rpx;
		padding: 24rpx;
		margin-bottom: 24rpx;
	}

	.content-item-top {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.content-item-title {
		font-family: PingFangHK, PingFangHK;
		font-weight: 500;
		font-size: 30rpx;
		color: #222222;
		line-height: 42rpx;
		display: flex;
	}

	.content-item-date {
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		line-height: 34rpx;
	}

	.content-item-text {
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #585858;
		line-height: 40rpx;
		padding: 20rpx 0;

		display: -webkit-box;
		/* 必须使用 flex 布局 */
		-webkit-box-orient: vertical;
		/* 垂直方向 */
		-webkit-line-clamp: 3;
		/* 限制显示行数 */
		overflow: hidden;
		/* 超出部分隐藏 */
		text-overflow: ellipsis;
		/* 超出部分显示省略号 */
	}

	.empty-review {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 48rpx 0;
	
		image {
			width: 328rpx;
			height: 208rpx;
			margin-bottom: 24rpx;
		}
	}
</style>